package cn.xshi.sys.web;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.xshi.common.base.BaseAction;
import cn.xshi.common.base.BasePage;
import cn.xshi.common.base.BaseResult;
import cn.xshi.sys.form.SysEncoderQRCodeForm;
import cn.xshi.sys.model.SysEncoderQRCode;
import cn.xshi.sys.service.SysEncoderQRCodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import cn.xshi.common.annotation.Auth;
import cn.xshi.common.entity.OauthAccountEntity;
import cn.xshi.common.util.StringUtil;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageInfo;
import javax.annotation.Resource;
/**
 * @Desc 平台二维码
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@RestController
@RequestMapping("/sysEncoderQRCode")
@Api(value = "平台二维码API",tags = "平台二维码API",description = "平台二维码API")
public class SysEncoderQRCodeController extends BaseAction {

	@Resource
	private SysEncoderQRCodeService sysEncoderqrcodeService;

	/**
	 * 查询平台二维码列表并分页
	 * @param sysEncoderQRCodeForm
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@GetMapping(value="/list")
	@Auth(value = "/sysEncoderQRCode/list",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	@ApiOperation(value="查询平台二维码列表并分页", notes="查询平台二维码列表并分页")
	public BasePage<List<SysEncoderQRCode>> getSysEncoderQRCodeListByCondition(SysEncoderQRCodeForm sysEncoderQRCodeForm,Integer pageNo, Integer pageSize){
		commonHPagerByPageNo(pageNo,pageSize);
		List<SysEncoderQRCode> sysEncoderQRCodeList = sysEncoderqrcodeService.getSysEncoderQRCodeListByCondition(sysEncoderQRCodeForm);
		PageInfo<SysEncoderQRCode> page = new PageInfo<SysEncoderQRCode>(sysEncoderQRCodeList);
		return outPageBootByPageNo(page,pageNo,pageSize);
	}

	/**
	 * 查询单个平台二维码
	 * @param id
	 */
	@GetMapping(value="/get/{id}")
	@Auth(value = "/sysEncoderQRCode/get",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	@ApiOperation(value="查询单个平台二维码", notes="查询单个平台二维码")
	public BaseResult<SysEncoderQRCode> getSysEncoderQRCodeById(@PathVariable("id")String id){
		SysEncoderQRCode sysEncoderQRCode = sysEncoderqrcodeService.getSysEncoderQRCodeById(id);
		if(!StringUtil.isEmpty(sysEncoderQRCode.getCreateId())){
			OauthAccountEntity createBy = getAccount(sysEncoderQRCode.getCreateId());
			if(null != createBy){
				sysEncoderQRCode.setCreateBy(createBy.getName());
			}
		}
		if(!StringUtil.isEmpty(sysEncoderQRCode.getUpdateId())){
			OauthAccountEntity modifiedBy = getAccount(sysEncoderQRCode.getUpdateId());
			if(null != modifiedBy){
				sysEncoderQRCode.setModifiedBy(modifiedBy.getName());
			}
		}
		return outDataStr(sysEncoderQRCode);
	}

	/**
	 * 添加
	 * @param encoderqrcode
	 */
	@PostMapping(value="/add")
	@ApiOperation(value="创建单个平台二维码", notes="创建单个平台二维码")
	public BaseResult addSysEncoderQRCode(@RequestBody SysEncoderQRCode encoderqrcode){
		int i = 0;
		if(null != encoderqrcode){
			encoderqrcode.setId(toUUID());
			i= sysEncoderqrcodeService.addSysEncoderQRCode(encoderqrcode);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 * 修改
	 * @param encoderqrcode
	 */
	@PutMapping(value="/update")
	@ApiOperation(value="编辑单个平台二维码", notes="编辑单个平台二维码")
	public BaseResult updateSysEncoderQRCode(@RequestBody SysEncoderQRCode encoderqrcode){
		int i = 0;
		if(null != encoderqrcode){
			i= sysEncoderqrcodeService.updateSysEncoderQRCode(encoderqrcode);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 * 删除
	 * @param id
	 */
	@DeleteMapping(value="/delete")
	@ApiOperation(value="删除平台二维码", notes="删除平台二维码")
	public BaseResult delSysEncoderQRCode(String id){
		int i = 0;
		if(!StringUtil.isEmpty(id)){
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("id",id.split(","));
			i= sysEncoderqrcodeService.delSysEncoderQRCode(condition);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}
}
